// 引入深拷贝
import { deepClone } from '../../utils/func'

import { GET_TOKEN } from '../actionTypes'

const defaultState = {
    token: window.localStorage.getItem('token') || ''
} 

export default function user(state = defaultState,action){
    //深度拷贝state
    let newState = deepClone(state)
    switch(action.type){
        case GET_TOKEN :
            window.localStorage.setItem('token',action.data)
            newState.token = action.data
            return newState
        default:
            return state
    }
    
} 